<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Basic CMSIS Example</title>
<title>CMSIS-Core (Cortex-A): Basic CMSIS Example</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="cmsis.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="printComponentTabs.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 46px;">
  <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">CMSIS-Core (Cortex-A)
   &#160;<span id="projectnumber">Version 1.1.4</span>
   </div>
   <div id="projectbrief">CMSIS-Core support for Cortex-A processor-based devices</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<div id="CMSISnav" class="tabs1">
    <ul class="tablist">
      <script type="text/javascript">
		<!--
		writeComponentTabs.call(this);
		//-->
      </script>
	  </ul>
</div>
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('using_CMSIS.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title">Basic CMSIS Example </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>A typical example for using the CMSIS layer is provided below. The example is based on an unspecific Cortex-A9 Device.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="ARMCA9_8h.html">ARMCA9.h</a>&gt;</span>                              <span class="comment">// File name depends on device used</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">static</span> <span class="keyword">const</span> uint32_t TICK_RATE_HZ = 1000U;</div>
<div class="line"> </div>
<div class="line">uint32_t <span class="keyword">volatile</span> msTicks;                       <span class="comment">// Counter for millisecond Interval</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> SysTick_Handler( <span class="keywordtype">void</span> )</div>
<div class="line">{</div>
<div class="line">  msTicks++;                                     <span class="comment">// Increment Counter</span></div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">// We use the Private Tiemer (PTIM) of the Cortex-A9 FVP Model here.</span></div>
<div class="line"><span class="comment">// In general the available Timers are highly vendor specific for Cortex-A processors.</span></div>
<div class="line"><span class="keywordtype">void</span> private_timer_init(<span class="keywordtype">void</span>) {</div>
<div class="line"> </div>
<div class="line">  <a class="code" href="group__PTM__timer__functions.html#ga30516fed24977be8eecf3efd8b6a2fea">PTIM_SetLoadValue</a> ((<a class="code" href="group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6">SystemCoreClock</a>/TICK_RATE_HZ) - 1U);</div>
<div class="line">  <a class="code" href="group__PTM__timer__functions.html#gaabc1dba029389fe0e2a6297952df7972">PTIM_SetControl</a> (<a class="code" href="group__PTM__timer__functions.html#ga34f0ceea142a4be1479cb552bf8bc4d1">PTIM_GetControl</a>() | 7U);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">/* Install SysTick_Handler as the interrupt function for PTIM */</span></div>
<div class="line">  <a class="code" href="group__irq__ctrl__gr.html#gac1fcc16fb8e488d315cfa496f1d71db3">IRQ_SetHandler</a>((<a class="code" href="irq__ctrl_8h.html#ac62964c04a7fed2c84aeea9e34f415e2">IRQn_ID_t</a>)<a class="code" href="ARMCA9_8h.html#a666eb0caeb12ec0e281415592ae89083a116d3d8a9fcc5fef99becc9d25a56249">PrivTimer_IRQn</a>, SysTick_Handler);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">/* Determine number of implemented priority bits */</span></div>
<div class="line">  <a class="code" href="group__irq__ctrl__gr.html#gaa90aed20ac94420fff4bbbf55c12d4c2">IRQ_SetPriority</a> ((<a class="code" href="irq__ctrl_8h.html#ac62964c04a7fed2c84aeea9e34f415e2">IRQn_ID_t</a>)<a class="code" href="ARMCA9_8h.html#a666eb0caeb12ec0e281415592ae89083a116d3d8a9fcc5fef99becc9d25a56249">PrivTimer_IRQn</a>, <a class="code" href="group__irq__priority__defs.html#gabaa4e91ab84dbe5f669080af6d0d81fa">IRQ_PRIORITY_Msk</a>);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">/* Set lowest priority -1 */</span></div>
<div class="line">  <a class="code" href="group__irq__ctrl__gr.html#gaa90aed20ac94420fff4bbbf55c12d4c2">IRQ_SetPriority</a> ((<a class="code" href="irq__ctrl_8h.html#ac62964c04a7fed2c84aeea9e34f415e2">IRQn_ID_t</a>)<a class="code" href="ARMCA9_8h.html#a666eb0caeb12ec0e281415592ae89083a116d3d8a9fcc5fef99becc9d25a56249">PrivTimer_IRQn</a>, <a class="code" href="group__GIC__functions.html#ga397048004654f792649742f95bf8ae67">GIC_GetPriority</a>((<a class="code" href="irq__ctrl_8h.html#ac62964c04a7fed2c84aeea9e34f415e2">IRQn_ID_t</a>)<a class="code" href="ARMCA9_8h.html#a666eb0caeb12ec0e281415592ae89083a116d3d8a9fcc5fef99becc9d25a56249">PrivTimer_IRQn</a>)-1);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">/* Enable IRQ */</span></div>
<div class="line">  <a class="code" href="group__irq__ctrl__gr.html#ga4ad780a3dc23a1b6222de8adcd7c20a7">IRQ_Enable</a> ((<a class="code" href="irq__ctrl_8h.html#ac62964c04a7fed2c84aeea9e34f415e2">IRQn_ID_t</a>)<a class="code" href="ARMCA9_8h.html#a666eb0caeb12ec0e281415592ae89083a116d3d8a9fcc5fef99becc9d25a56249">PrivTimer_IRQn</a>);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">/* Delay execution for given amount of ticks */</span></div>
<div class="line"><span class="keywordtype">void</span> Delay(uint32_t ticks)  {</div>
<div class="line">  uint32_t tgtTicks = msTicks + ticks;             <span class="comment">// target tick count to delay execution to</span></div>
<div class="line">  <span class="keywordflow">while</span> (msTicks == tgtTicks)  {</div>
<div class="line">    <a class="code" href="group__CMSIS__Core__InstructionInterface.html#gaac6cc7dd4325d9cb40d3290fa5244b3d">__WFE</a> ();                                      <span class="comment">// Power-Down until next Event/Interrupt</span></div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">/* main function */</span></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">  <span class="comment">/* Initialize device HAL here */</span></div>
<div class="line">  private_timer_init();</div>
<div class="line"> </div>
<div class="line">  <span class="keyword">static</span> uint8_t ledState = 0;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">/* Infinite loop */</span></div>
<div class="line">  <span class="keywordflow">while</span> (1)</div>
<div class="line">  {</div>
<div class="line">    <span class="comment">/* Add application code here */</span></div>
<div class="line">    ledState = !ledState;</div>
<div class="line">    Delay(500);</div>
<div class="line">  }</div>
<div class="line">}</div>
</div><!-- fragment --><p>CMSIS-Pack provides the <b>#define CMSIS_header_file</b> in <a href="../../Pack/html/pdsc_components_pg.html#RTE_Components_h"><b>RTE_Components.h</b></a> which gives you access to the <b><em>device</em>.h</b> file of a project. This allows you to generate generic software components that use the device selected in a project.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;RTE_Components.h&quot;</span>     <span class="comment">// include information about project configuration</span></div>
<div class="line"><span class="preprocessor">#include CMSIS_device_header    // include &lt;device&gt;.h file</span></div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<div class="ttc" id="airq__ctrl_8h_html_ac62964c04a7fed2c84aeea9e34f415e2"><div class="ttname"><a href="irq__ctrl_8h.html#ac62964c04a7fed2c84aeea9e34f415e2">IRQn_ID_t</a></div><div class="ttdeci">int32_t IRQn_ID_t</div><div class="ttdoc">Interrupt ID number data type.</div><div class="ttdef"><b>Definition:</b> irq_ctrl.h:45</div></div>
<div class="ttc" id="agroup__PTM__timer__functions_html_gaabc1dba029389fe0e2a6297952df7972"><div class="ttname"><a href="group__PTM__timer__functions.html#gaabc1dba029389fe0e2a6297952df7972">PTIM_SetControl</a></div><div class="ttdeci">__STATIC_INLINE void PTIM_SetControl(uint32_t value)</div><div class="ttdoc">Configure the timer using its CONTROL register.</div><div class="ttdef"><b>Definition:</b> core_ca.h:1654</div></div>
<div class="ttc" id="agroup__irq__priority__defs_html_gabaa4e91ab84dbe5f669080af6d0d81fa"><div class="ttname"><a href="group__irq__priority__defs.html#gabaa4e91ab84dbe5f669080af6d0d81fa">IRQ_PRIORITY_Msk</a></div><div class="ttdeci">#define IRQ_PRIORITY_Msk</div><div class="ttdoc">Interrupt priority value bit-mask.</div><div class="ttdef"><b>Definition:</b> irq_ctrl.h:90</div></div>
<div class="ttc" id="agroup__irq__ctrl__gr_html_ga4ad780a3dc23a1b6222de8adcd7c20a7"><div class="ttname"><a href="group__irq__ctrl__gr.html#ga4ad780a3dc23a1b6222de8adcd7c20a7">IRQ_Enable</a></div><div class="ttdeci">int32_t IRQ_Enable(IRQn_ID_t irqn)</div><div class="ttdoc">Enable interrupt.</div></div>
<div class="ttc" id="agroup__PTM__timer__functions_html_ga34f0ceea142a4be1479cb552bf8bc4d1"><div class="ttname"><a href="group__PTM__timer__functions.html#ga34f0ceea142a4be1479cb552bf8bc4d1">PTIM_GetControl</a></div><div class="ttdeci">__STATIC_INLINE uint32_t PTIM_GetControl(void)</div><div class="ttdef"><b>Definition:</b> core_ca.h:1662</div></div>
<div class="ttc" id="aARMCA9_8h_html_a666eb0caeb12ec0e281415592ae89083a116d3d8a9fcc5fef99becc9d25a56249"><div class="ttname"><a href="ARMCA9_8h.html#a666eb0caeb12ec0e281415592ae89083a116d3d8a9fcc5fef99becc9d25a56249">PrivTimer_IRQn</a></div><div class="ttdeci">@ PrivTimer_IRQn</div><div class="ttdef"><b>Definition:</b> ARMCA9.h:69</div></div>
<div class="ttc" id="agroup__irq__ctrl__gr_html_gaa90aed20ac94420fff4bbbf55c12d4c2"><div class="ttname"><a href="group__irq__ctrl__gr.html#gaa90aed20ac94420fff4bbbf55c12d4c2">IRQ_SetPriority</a></div><div class="ttdeci">int32_t IRQ_SetPriority(IRQn_ID_t irqn, uint32_t priority)</div><div class="ttdoc">Set interrupt priority value.</div></div>
<div class="ttc" id="aARMCA9_8h_html"><div class="ttname"><a href="ARMCA9_8h.html">ARMCA9.h</a></div></div>
<div class="ttc" id="agroup__irq__ctrl__gr_html_gac1fcc16fb8e488d315cfa496f1d71db3"><div class="ttname"><a href="group__irq__ctrl__gr.html#gac1fcc16fb8e488d315cfa496f1d71db3">IRQ_SetHandler</a></div><div class="ttdeci">int32_t IRQ_SetHandler(IRQn_ID_t irqn, IRQHandler_t handler)</div><div class="ttdoc">Register interrupt handler.</div></div>
<div class="ttc" id="agroup__system__init__gr_html_gaa3cd3e43291e81e795d642b79b6088e6"><div class="ttname"><a href="group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6">SystemCoreClock</a></div><div class="ttdeci">uint32_t SystemCoreClock</div><div class="ttdoc">Variable to hold the system core clock value.</div><div class="ttdef"><b>Definition:</b> Ref_SystemAndClock.txt:67</div></div>
<div class="ttc" id="agroup__CMSIS__Core__InstructionInterface_html_gaac6cc7dd4325d9cb40d3290fa5244b3d"><div class="ttname"><a href="group__CMSIS__Core__InstructionInterface.html#gaac6cc7dd4325d9cb40d3290fa5244b3d">__WFE</a></div><div class="ttdeci">#define __WFE</div><div class="ttdoc">Wait For Event.</div><div class="ttdef"><b>Definition:</b> cmsis_armcc.h:107</div></div>
<div class="ttc" id="agroup__GIC__functions_html_ga397048004654f792649742f95bf8ae67"><div class="ttname"><a href="group__GIC__functions.html#ga397048004654f792649742f95bf8ae67">GIC_GetPriority</a></div><div class="ttdeci">__STATIC_INLINE uint32_t GIC_GetPriority(IRQn_Type IRQn)</div><div class="ttdoc">Read the current interrupt priority from GIC's IPRIORITYR register.</div><div class="ttdef"><b>Definition:</b> core_ca.h:1342</div></div>
<div class="ttc" id="agroup__PTM__timer__functions_html_ga30516fed24977be8eecf3efd8b6a2fea"><div class="ttname"><a href="group__PTM__timer__functions.html#ga30516fed24977be8eecf3efd8b6a2fea">PTIM_SetLoadValue</a></div><div class="ttdeci">__STATIC_INLINE void PTIM_SetLoadValue(uint32_t value)</div><div class="ttdoc">Set the load value to timers LOAD register.</div><div class="ttdef"><b>Definition:</b> core_ca.h:1623</div></div>
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="using_pg.html">Using CMSIS in Embedded Applications</a></li>
    <li class="footer">Generated on Tue Mar 17 2020 15:01:19 for CMSIS-Core (Cortex-A) Version 1.1.4 by Arm Ltd. All rights reserved.
	<!--
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.17 
	-->
	</li>
  </ul>
</div>
</body>
</html>
